package Vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import Controlador.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ConsultarCliente extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel jLabel1;
	private JButton consultar;
	private JTextField resultado;
	private JLabel jLabel2;
	private JTextField dni;
	private Sistema sistema;
	private JTextField nombre;
	private JLabel jLabel3;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ConsultarCliente inst = new ConsultarCliente();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public ConsultarCliente() {
		super();
		sistema = new Sistema();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("Dni: ");
				jLabel1.setBounds(12, 24, 88, 16);
			}
			{
				dni = new JTextField();
				getContentPane().add(dni);
				dni.setBounds(118, 21, 175, 23);
			}
			{
				consultar = new JButton();
				getContentPane().add(consultar);
				consultar.setText("Consultar");
				consultar.setBounds(118, 209, 105, 23);
				consultar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						VistaTarjeta v = sistema.consultarCliente(dni.getText());
						
						if (v != null){
							nombre.setText(v.getNombre());
							resultado.setText(String.valueOf(v.getLimite()));
							
						}
					}
				});
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Limite Total");
				jLabel2.setBounds(12, 137, 94, 16);
			}
			{
				resultado = new JTextField();
				getContentPane().add(resultado);
				resultado.setBounds(118, 134, 175, 23);
			}
			{
				jLabel3 = new JLabel();
				getContentPane().add(jLabel3);
				jLabel3.setText("Nombre:");
				jLabel3.setBounds(12, 59, 88, 16);
			}
			{
				nombre = new JTextField();
				getContentPane().add(nombre);
				nombre.setBounds(118, 56, 175, 23);
				nombre.setEditable(false);
			}
			pack();
			this.setSize(392, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
